#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Author: IcySun
# 脚本功能：爬去fuzzall结果
import sys
reload(sys)
sys.setdefaultencoding('utf-8')

import urllib2
import urllib
import re
from cookielib import CookieJar
domain = raw_input("input the domain:")
reui = re.compile(r'\s*?<a href="(.*?)" target="_blank" rel="nofollow">.*?</a>[\s\S]*?</td>[\s\S]*?<td>\[&quot;(.*?)&quot;\]</td>')
count = 1
loginurl = 'http://www.fuzzall.com/login'
cj = CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
token = opener.open(loginurl).read()[588:628]
opener.addheaders =[
                ('User-Agent','Mozilla/5.0 (Windows NT 6.2; WOW64; rv:36.0) Gecko/20100101 Firefox/36.0'),
                ('Accept','text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'),
                ('Accept-Encoding','gzip, deflate'),
                ('Connection', 'keep-alive'),
                ('X-Forwarded-For','127.0.0.1')           
                ]
formdata = {'_token':token,
            'email':'user@domain.com', #自行注册
            'password':'password'}     #自行注册
data_encoded = urllib.urlencode(formdata)
response = opener.open(loginurl, data_encoded,timeout=10)
for i in xrange(1,10):
    url = 'http://www.fuzzall.com/search/' + domain +' ?page=' + str(i)
    content = opener.open(url).read()
    urls = re.findall(reui, content)
    for url,ip in urls:
        ip = ip.replace("&quot;", "")
        print count,url,ip
        count+=1
        with open(domain+'.txt','a') as f:
            f.write(str(count)+'\t'+url+'\t\t\t\t'+ip+'\n')